package com.redis_with_springboot;

import com.redis_with_springboot.utils.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;


/**
 * @ClassName: TestRedis
 * @Author: ZhangYue26
 * @Description: 测试Redis
 * @Date: 2020-10-23
 */
@Component
@EnableScheduling
public class TestRedis {

    @Autowired
    private RedisUtil redisUtil;

    private final static Integer indexDb = 10;

//    @Scheduled(initialDelay = 1000, fixedDelay = 1000)
    public void test() {
//        for (int i = 0; i < 100; i++) {
        String key = UUID.randomUUID().toString().replaceAll("-", "");


//        List<Long> list = new ArrayList(){{add(System.currentTimeMillis());add(System.currentTimeMillis());add(System.currentTimeMillis());add(System.currentTimeMillis());add(System.currentTimeMillis());add(System.currentTimeMillis());}};
//        redisUtil.set(key, list, indexDb,100l);
//        Object value = redisUtil.get(key, indexDb);
//        List<Long> value1 = (List<Long>) value;
//        redisUtil.delByIndexDb(indexDb,key);


        redisUtil.set(key, System.currentTimeMillis(), 10000000l);
        System.out.println(key);
        System.out.println(redisUtil.get(key,0));;
        redisUtil.del(key);
        redisUtil.set(key,System.currentTimeMillis(), 1);
        System.out.println(redisUtil.get(key, 1).toString());

    }

}
